
function addProduct(prdct) {
    if (!empty(prdct)) {
        var arr = getProductList();
        if (!contains(arr, prdct)) {
            arr.push(prdct);
            var newlist = getCookie("wms.productlist") + "," + prdct;
            setCookie("wms.productlist", newlist);
        }
    }
}

function InitHeight(){
	/* 高度设置  */
	var WinH = $(window).height();
	var CrH = $('.ContainerRight').height();
	var ClH = $('.ContainerLeft').height();
	if(CrH>ClH && CrH>WinH){
		$('.ContainerLeft').height(CrH+40);
	}else if(CrH>ClH && WinH>CrH){
		$('.ContainerLeft').height(WinH);
	}else{
		$('.ContainerLeft').height(ClH+20);
	}
}

function rightHua(){
	var plchimg = $('.ProductsDetails img').width();
	$('.ProductsDetails img').height(plchimg);
	var plch = $('.ProductsDetails').height();
	$('.AllContent').css({backgroundColor:'#f3f3f3'});
	$('.moreOperation p').css({paddingTop:plch/2-5,paddingBottom:plch/2-5});
	
	$('.ProductsDetails').on('click',function(){
		$(this).next('.moreOperation').show().animate({right:'-40%'},300);
		$(this).animate({left:'-60%'},300);
	});
	
	$('.prtsBack').on('click',function(){
		$(this).parent().animate({right:'-100%'},300);
		$(this).parent().prev().animate({left:'0%'},300);
	})
//	$('.ProductsListContent').on('swipeleft',function(){
//		$(this).find('.moreOperation').show().animate({right:'-40%'},300);
//		$(this).find('.ProductsDetails').animate({left:'-60%'},300);
//	});
//	
//	$('.ProductsListContent').on('swiperight',function(){
//		$(this).find('.moreOperation').animate({right:'-100%'},300,function(){
//			$(this).hide();
//		});
//		$(this).find('.ProductsDetails').animate({left:'0%'},300);
//	});
		
}

function getProductList() {
    return strtoarray(getCookie("wms.productlist"));
}
function clsProductList() {
    setCookie("wms.productlist", "");
}
/**
 * 企业客户端加载产品
 */
function loadProduct() {
    $.ajax({
        type: "GET",
        url: getServerUrl() + "/Open/Company/productlist", //与此php页面沟通
        dataType: 'json', //从php返回的值以 JSON方式 解释
        data: 'access_token='+getToken()+'&page_no='+getPageNo(), //
        success: function (json) {//如果调用php成功
            productlist = json.productlist;
            showProduct(productlist);
            showpage(json.total_results,json.page_no,json.page_size,getwindowhref());
        },
        error:function(json){
            alertMessage(json.errordescription);
        }
    });
}
function showProduct(clist) {
    productlist = clist;
    var chtml = '';
    //var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
            	chtml = chtml + '<div class="ProductsListContent">';
            	chtml = chtml + '<div class="ProductsDetails">';
    			chtml = chtml + '<ul>';
    			chtml = chtml + '<li><img width="100%" src="' + clist[i].pic_url + '"></li>';
		    	chtml = chtml + '<li>';
		    	chtml = chtml + '<p>' + clist[i].name + '</p>';
		    	chtml = chtml + '<p>' + clist[i].price + '</p>';
		    	chtml = chtml + '<p>' + clist[i].pid + '</p>';
		    	chtml = chtml + '</li>';
    			chtml = chtml + '</ul>';
    			chtml = chtml + '</div>';
    			
    			chtml = chtml + '<div class="moreOperation">';
    			chtml = chtml + '<p><a href="EditProduct.html?pid=' + clist[i].pid + '" >编辑</a></p>';
    			chtml = chtml + '<p onclick="removeproduct(\'' + clist[i].pid + '\');">删除</p>';
    			chtml = chtml + '<p class="prtsBack">取消</p>';
    			chtml = chtml + '</div>';
    			chtml = chtml + '</div>';
            	
                
            }
        }
    }

    $("#productList").html(chtml);
	rightHua()
}

/**
 * 企业客户端加载图片空间数据
 */
function loadPic() {
    $.ajax({
        type: "GET",
        url: getServerUrl() + "/Open/Company/piclist", //与此php页面沟通
        dataType: 'json', //从php返回的值以 JSON方式 解释
        data: 'access_token='+getToken()+'&page_no='+getPageNo(), //
        success: function (json) {//如果调用php成功
            piclist = json.piclist;
            showPic(piclist);
            showpage(json.total_results,json.page_no,json.page_size,getwindowhref());
        },
        error:function(json){
            alertMessage(json.errordescription);
        }
    });
}
function showPic(clist) {
    piclist = clist;
    var chtml = '';
    //var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
            	chtml = chtml + '<div class="ProductsListContent">';
            	chtml = chtml + '<div class="ProductsDetails" style="background-image: url(./images/compile2.png)">';
    			chtml = chtml + '<ul>';
    			chtml = chtml + '<li><img width="100%" src="' + clist[i].image + '"></li>';
		    	chtml = chtml + '<li>';
		    	chtml = chtml + '<p>' + clist[i].title + '</p>';
		    	chtml = chtml + '<p>' + clist[i].groupname + '</p>';
		    	chtml = chtml + '</li>';
    			chtml = chtml + '</ul>';
    			chtml = chtml + '</div>';
    			
    			chtml = chtml + '<div class="moreOperation">';
    			chtml = chtml + '<p><a href="editpic.html?id=' + clist[i].id + '" >编辑</a></p>';
    			chtml = chtml + '<p  onclick="removepic(\'' + clist[i].id + '\');">删除</p>';
    			chtml = chtml + '<p class="prtsBack">取消</p>';
    			chtml = chtml + '</div>';
    			chtml = chtml + '</div>';
            	
            }
        }
    }

    $("#piclist").html(chtml);
	rightHua()
}

/**
 * 企业客户端加载文件数据
 */
function loadFile() {
    $.ajax({
        type: "GET",
        url: getServerUrl() + "/Open/Company/filelist", //与此php页面沟通
        dataType: 'json', //从php返回的值以 JSON方式 解释
        data: 'access_token='+getToken()+'&page_no='+getPageNo(), //
        success: function (json) {//如果调用php成功
            filelist = json.filelist;
            showFile(filelist);
            showpage(json.total_results,json.page_no,json.page_size,getwindowhref());
        },
        error:function(json){
            alertMessage(json.errordescription);
        }
    });
}
function showFile(clist) {
    filelist = clist;
    var chtml = '';
    //var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
                chtml = chtml + '<tr>';
                chtml = chtml + "<td class='check'><input class='elect' name='chk_list' type='checkbox'></td>";
                chtml = chtml + '<td>' + clist[i].note + '</td>';
                chtml = chtml + '<td>' + clist[i].fileid + '</td>';
                chtml = chtml + '<td>' + clist[i].groupname + '</td>';
                chtml = chtml + '<td>' + clist[i].created + '</td>';
                chtml = chtml + '<td>';
                chtml = chtml + '<button onclick="removefile(\'' + clist[i].fileid + '\');"><i class="iconfont  icon-shanchu"></i>删除</button>';
                chtml = chtml + '</td>';
                chtml = chtml + '</tr>';
            }
        }
    }

    $("#filelist").html(chtml);
	InitHeight();
}

/**
 * 企业客户端加载产品批次
 */
function loadProductlot() {
    var pid = $_GET['pid'];
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/Company/lotlist", //与此php页面沟通
        dataType: 'json', //从php返回的值以 JSON方式 解释
        data: 'access_token='+getToken()+'&page_no='+getPageNo()+'&pid='+pid, //
        success: function (json) {//如果调用php成功
            $("#name").val(json.pname);
            $("#product_name").html(json.pname);
            lotlist = json.lotlist;
            showlot(lotlist);
            showpage(json.total_results,json.page_no,json.page_size,getwindowhref());
        },
        error:function(json){
            alertMessage(json.errordescription);
        }
    });
}
function showlot(clist) {
    lotlist = clist;
    var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
                chtml = chtml + '<tr>';
                chtml = chtml + "<td class='check'><input class='elect' name='chk_list' type='checkbox'></td>";
                chtml = chtml + '<td>' + clist[i].lot_no + '</td>';
                chtml = chtml + '<td>' + clist[i].status + '</td>';
                chtml = chtml + '<td>' + clist[i].guarantee_date + '</td>';
                chtml = chtml + '<td>' + clist[i].quantity + '</td>';
                chtml = chtml + '<td>' + clist[i].production_date + '</td>';
                chtml = chtml + '<td>' + clist[i].end_date + '</td>';
                chtml = chtml + '<td>' + clist[i].note + '</td>';
                chtml = chtml + '<td>';
                chtml = chtml + '<p><a href="EditLot.html?id=' + clist[i].id + '"><i  class="iconfont  icon-bianji"></i>编辑</a></p>';
                chtml = chtml + '<p><button onclick="removelot(\'' + clist[i].id + '\');"><i  class="iconfont  icon-shanchu"></i>删除</button></p>';
                chtml = chtml + '</td>';
                chtml = chtml + '</tr>';
            }
        }
    }

    $("#lotlist").html(chtml);
	InitHeight();
}

/**
 * 企业客户端加载网点
 */
function loadBranch() {
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/Company/branchlist", //与此php页面沟通
        dataType: 'json', //从php返回的值以 JSON方式 解释
        data: 'access_token='+getToken()+'&page_no='+getPageNo(), //
        success: function (json) {//如果调用php成功
            branchlist = json.branchlist;
            showBranch(branchlist);
            showpage(json.total_results,json.page_no,json.page_size,getwindowhref());
        },
        error:function(json){
            alertMessage(json.errordescription);
        }
    });
}
function showBranch(clist) {
    var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
                chtml = chtml + '<div class="ProductsListContent">';
            	chtml = chtml + '<div class="ProductsDetails">';
    			chtml = chtml + '<ul>';
    			chtml = chtml + '<li><img width="100%" src="' + clist[i].branch_pic + '"></li>';
		    	chtml = chtml + '<li>';
		    	chtml = chtml + '<p>' + clist[i].name + '</p>';
		    	chtml = chtml + '<p>' + clist[i].phone + '</p>';
		    	chtml = chtml + '<p>' + clist[i].link_man + '</p>';
		    	chtml = chtml + '</li>';
    			chtml = chtml + '</ul>';
    			chtml = chtml + '</div>';
    			
    			chtml = chtml + '<div class="moreOperation">';
    			chtml = chtml + '<p><a href="EditBranch.html?bid=' + clist[i].bid + '" >编辑</a></p>';
    			chtml = chtml + '<p onclick="removebranch(\'' + clist[i].bid + '\');">删除</p>';
    			chtml = chtml + '<p class="prtsBack">取消</p>';
    			chtml = chtml + '</div>';
    			chtml = chtml + '</div>';
            }
        }
    }

    $("#ScreentoneList").html(chtml);
	rightHua();
}
/*
*加加载企业用户
*/
function loadCompanyUser() {
    var datas = {access_token:getToken()};
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/ComSys/userlist",
        dataType: 'json',
        data: datas,
        success: function (json) {
            userArr = json.userlist;
            showCompanyuser(userArr);
        },
        error: function () {
            alertMessage("请检查网络连接！");
        }
    });
}
function showCompanyuser(clist) {
    var chtml = '';
    //var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            //alert(clist[i]);
            if (!empty(clist[i])) {
                chtml = chtml + '<tr>';
                chtml = chtml + "<td class='check'><input class='elect' name='chk_list' type='checkbox'></td>";
                chtml = chtml + '<td>' + clist[i].account + '</td>';
                chtml = chtml + '<td>' + clist[i].nickname + '</td>';
                chtml = chtml + '<td>' + clist[i].mobile + '</td>';
                chtml = chtml + '<td>' + clist[i].last_login_time + '</td>';
                chtml = chtml + '<td>';
                chtml = chtml + '<button class="btn btn-danger removeUser" uid="' + clist[i].uid + '"><i class="iconfont icon-shanchu"></i>删除</button>';
                chtml = chtml + ' <button class="btn btn-success resetCompanyUser" uid="' + clist[i].uid + '"><i class="iconfont icon-xitongshezhi"></i>重置密码</button>';
                chtml = chtml + '</td>';
                chtml = chtml + '</tr>';
            }
        }
    }
    //alert(chtml);
    $("#companylist").html(chtml);
	InitHeight();
}

function loadBranchUser() {
    var datas = {bid: getBranchId(),access_token:getToken(),page_no:getPageNo()};
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/Company/userlist",
        dataType: 'json',
        data: datas,
        success: function (json) {
            userArr = json.userlist;
            showBranchuser(userArr);
            showpage(json.total_results,json.page_no,json.page_size,getwindowhref());
        },
        error: function () {
            alertMessage("请检查网络连接！");
        }


    });
}

function showBranchuser(clist) {
    var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
                chtml = chtml + '<tr>';
                chtml = chtml + "<td class='check'><input class='elect' name='chk_list' type='checkbox'></td>";
                chtml = chtml + '<td>' + clist[i].account + '</td>';
                chtml = chtml + '<td>' + clist[i].mobile + '</td>';
                chtml = chtml + '<td>' + clist[i].last_login_time + '</td>';
                chtml = chtml + '<td>';
                chtml = chtml + '<button class="btn btn-danger removeUser" uid="' + clist[i].uid + '"><i class="fa fa-times"></i>删除</button>';
//              chtml = chtml + ' <button class="btn btn-info catToken" uid="' + clist[i].uid + '"><i class="fa fa-eye"></i>查看Token</button>';
                chtml = chtml + ' <button class="btn btn-success resetCompanyUser" uid="' + clist[i].uid + '"><i class="fa fa-refresh"></i>重置密码</button>';
                chtml = chtml + '</td>';
                chtml = chtml + '</tr>';
            }
        }
    }
    //alert(chtml);
    $("#branchlist").html(chtml);
	InitHeight();
	
	/* 遮罩  */
	$('.catToken').click(function(){
		$('.theme-popover-mask1').fadeIn(100);
		$('.theme-popover1').slideDown(200);
		$('body').css({overflow:'hidden'});
	})
	$('.theme-popover-mask1,.exit,.guanbi,.save').click(function(){
		$('.theme-popover-mask1').fadeOut(100);
		$('.theme-popover1').slideUp(200);
		$('body').css({overflowY:'scroll'});
	})
}

// 加载代理标签批次
function loadProxyTaglot() {
            var cid = $("#cidname").text();
    var datas = {access_token:getToken(),page_no:getPageNo(),cid:cid};
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/Proxy/taglotlist",
        dataType: 'json',
        data: datas,
        success: function (json) {
            if(json.result == "1"){
                tagArr = json.taglotlist;
                showProxyTaglot(tagArr);
                showpage(json.total_results,json.page_no,json.page_size,getwindowhref());
            }else{
                alertMessage(json.error_description);
            }

        },
        error: function () {
            alertMessage("请检查网络连接！");
        }
    });
}

function showProxyTaglot(clist) {
    var SiteUrl = getServerUrl();
    var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
                chtml = chtml + '<tr>';
                chtml = chtml + '<td>' + clist[i].lot + '</td>';
                chtml = chtml + '<td>' + clist[i].start_code + '</td>';
                chtml = chtml + '<td>' + clist[i].package_num + '</td>';
                chtml = chtml + '<td>' + clist[i].created + '</td>';
                chtml = chtml + '<td>' + clist[i].status + '</td>';
                chtml = chtml + '<td>';
                if(clist[i].status == '申请'){
                    chtml = chtml + ' <button class="btn btn-info catTag" uid="' + clist[i].lot + '">申请中</button>';
                }else if(clist[i].status == '完成'){
                    chtml = chtml + ' <a class="btn btn-info download_Tag" target="_blank" uid="' + clist[i].lot + '" href="'+SiteUrl+'/Open/D/downfile?filename='+clist[i].cid+'/'+clist[i].lot+'"><i class="fa fa-download"></i>下载</button>';
                }
                chtml = chtml + '</td>';
                chtml = chtml + '</tr>';
            }
        }
    }
    //alert(chtml);
    $("#Proxytaglotlist").html(chtml);
	InitHeight();
}

// 加载标签批次
function loadTaglot() {
    var datas = {access_token:getToken(),page_no:getPageNo()};
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/Comtag/taglotlist",
        dataType: 'json',
        data: datas,
        success: function (json) {
            if(json.result == "1"){
                tagArr = json.taglotlist;
                showTaglot(tagArr);
                showpage(json.total_results,json.page_no,json.page_size,getwindowhref());
            }else{
                alertMessage(json.error_description);
            }

        },
        error: function () {
            alertMessage("请检查网络连接！");
        }
    });
}

function showTaglot(clist) {
    var SiteUrl = getServerUrl();
    var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
                chtml = chtml + '<tr>';
                chtml = chtml + '<td>' + clist[i].lot + '</td>';
                chtml = chtml + '<td>' + clist[i].start_code + '</td>';
                chtml = chtml + '<td>' + clist[i].package_num + '</td>';
                chtml = chtml + '<td>' + clist[i].created + '</td>';
                chtml = chtml + '<td>' + clist[i].status + '</td>';
                chtml = chtml + '<td>';
                if(clist[i].status == '申请'){
                    chtml = chtml + ' <button class="btn btn-info catTag" uid="' + clist[i].lot + '">申请中</button>';
                }else if(clist[i].status == '完成'){
                    chtml = chtml + ' <a class="btn btn-info download_Tag" target="_blank" uid="' + clist[i].lot + '" href="'+SiteUrl+'/Open/D/downfile?filename='+clist[i].cid+'/'+clist[i].lot+'"><i class="fa fa-download"></i>下载</button>';
                }
                chtml = chtml + '</td>';
                chtml = chtml + '</tr>';
            }
        }
    }
    //alert(chtml);
    $("#taglotlist").html(chtml);
}

// 加载标签
function loadTag() {
    var datas = {bid: getBranchId(),access_token:getToken()};
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/Comtag/taglist",
        dataType: 'json',
        data: datas,
        success: function (json) {
            tagArr = json.taglist;
            showTag(tagArr);
            //showpage(json.total_results,json.page_no,json.page_size,getwindowhref());
        },
        error: function () {
            alertMessage("请检查网络连接！");
        }
    });
}

function showTag(clist) {
    var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
                chtml = chtml + '<tr>';
                chtml = chtml + '<td><input type="checkbox" class="" name="item_no" value="' + clist[i].item_no + '"></td>';
                chtml = chtml + '<td>' + '<button class="btn btn-info" onclick="showBarcode(\'' + clist[i].bid+'\');"><i class="fa fa-user"></i>查看二维码</button>' + '</td>';
                chtml = chtml + '<td>' + clist[i].item_no + '</td>';
                chtml = chtml + '<td>' + clist[i].pname + '</td>';
                chtml = chtml + '<td>' + clist[i].status + '</td>';
                chtml = chtml + '<td>' + clist[i].updated + '</td>';
                chtml = chtml + '<td>';
                chtml = chtml + '<p><a href="trackinglist.html?item_no=' + clist[i].item_no+ '" class="btn btn-success">溯源</a></p>';
                chtml = chtml + '<p><a href="cattag.html?item_no=' + clist[i].item_no+ '" class="btn btn-info"><i class="fa fa-eye"></i>查看标签</a></p>';
                if(getUserRole() !=3){
                    chtml = chtml + '<p><a href="edittag.html?item_no=' + clist[i].item_no+ '" class="btn btn-info "><i class="fa fa-edit"></i>编辑</a></p>';
                    chtml = chtml + '<p><button class="btn btn-danger" onclick="removeTag(\'' + clist[i].item_no + '\');"><i class="fa fa-times"></i>删除</button></p>';
                }
                chtml = chtml + '</td>';
                chtml = chtml + '</tr>';
            }
        }

    }
    $("#taglist").html(chtml);
	InitHeight();
}

/**
 * 企业客户端加载标签溯源
 */
function loadTrack() {
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/Comtag/tagtrack", //与此php页面沟通
        dataType: 'json', //从php返回的值以 JSON方式 解释
        data: 'access_token='+getToken()+'&item_no='+$_GET['item_no'], //
        success: function (json) {//如果调用php成功
            tracklist = json;
            showTrack(tracklist);

        },
        error:function(json){
            alertMessage(json.error_description);
        }
    });
}
function showTrack(clist) {
    var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
                
                chtml= chtml+ '<div class="TraceabilityPiece">'
	                                	+'<div class="TtyLeft">'
	                                        +'<ul>'
	                                        	+'<li class="TimeStyle">'
	                                        		+'<p>'+clist[i].start_date+'</p>'
	                                        		+'<p><a>'+ clist[i].start_date +'</a></p>'
	                                        	+'</li>'
	                                        +'</ul>'
	                                	+'</div>'
	                                	
	                                	+'<div class="TtyRight">'
	                                		+'<img class="leftImg" src="img/left.png">'
	                                		+'<ul>'
	                                			+'<li>'
	                                				+'<p><img src='+ clist[i].source_pic +'></p>'
	                                				+'<span class="ScreentoneName">'+ clist[i].from_name +'</span>'
	                                			+'</li>'
	                                			+'<li>'
	                                				+'<p><i class="iconfont icon-jiantou-copy2"></i>&nbsp;上移</p>'
	                                				+'<p><a href="editlottrack.html?id=' + clist[i].id + '"><i class="iconfont icon-bianji"></i>&nbsp;编辑</a></p>'
	                                				+'<p onclick="removetrack(\'' + clist[i].id + '\');"><i class="iconfont icon-shanchu"></i>&nbsp;删除</p>'
	                                				+'<p><i class="iconfont icon-jiantou-copy1"></i>&nbsp;下移</p>'
	                                			+'</li>'
	                                		+'</ul>'
	                                		+'<i class="circle"></i>'
											+'<div class="switchq sh1">'
	                            				+'<a class="nonefonts">隐藏</a>'
	                            				+'<img class="SlideImg" src="img/circle.png">'
	                            				+'<input type="checkbox" name="SlideCheckbox" id="control" class="control">'
	                            				+'<label for="control" class="checkbox"></label>'
											+'</div>'
	                                	+'</div>'	
	                            	+'</div>';
            }
        }
    }
    $("#tracklist").html(chtml);
	InitHeight();
}

/**
 * 企业客户端加载默认产品溯源
 */
function loadlotTrack() {
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/ComSys/prosource", //与此php页面沟通
        dataType: 'json', //从php返回的值以 JSON方式 解释
        data: 'access_token='+getToken()+'&pid='+$_GET['pid'], //
        success: function (json) {//如果调用php成功
            tracklist = json;
            showlotTrack(tracklist);

        },
        error:function(json){
            alertMessage(json.error_description);
        }
    });
}

/* 隐藏溯源   */
function hideTty(){
	$('.switchq').on('click',function(){
		if($(this).find('.control').prop("checked")){    //判断elect是否被选中
			$(this).find('.SlideImg').animate({left:'-5px'},200,function(){
				$(this).parent('.switchq').addClass('sh2');
				$(this).parents('.TraceabilityPiece').css({opacity:'0.2'});
			});
		}else{
			$(this).find('.SlideImg').animate({left:'40px'},200,function(){
				$(this).parent('.switchq').removeClass('sh2');
				$(this).parents('.TraceabilityPiece').css({opacity:'1'});
			});
			
		}
	})
}

function showlotTrack(clist) {
    var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
            	chtml= chtml+ '<div class="ChotingTtyLeft">'
								+'<p>'+ clist[i].start_date.substring(0,4)+'</p>'
								+'<p>'+ clist[i].start_date.substring(5,10)+'</p>'
							+'</div>'
							
							+'<div class="ChotingTtyRight" style="border-left:2px solid #6CC83A;">'
								+'<i></i>'
								+'<p class="SKheightImg"><img width="100%" src="'+ clist[i].source_pic +'"></p>'
								+'<p class="BranchName2">'+ clist[i].fname +'</p>'
							+'</div>';
            }
        }
    }
	
    $("#CentralBlock").html(chtml);
	$('.ChothingTtyTitle').show();
	hideTty();
	var strwt = $('.SKheightImg').width();
	$('.SKheightImg').height(strwt/2);
}

// 加载批量发货文件列表
function loadFilelot() {
    var datas = {access_token:getToken(),page_no:getPageNo()};
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/Comtag/filelotlist",
        dataType: 'json',
        data: datas,
        success: function (json) {
            if(json.result == "1"){
                filelist = json.filelist;
                showFilelot(filelist);
                showpage(json.total_results,json.page_no,json.page_size,getwindowhref());
            }else{
                alertMessage(json.error_description);
            }

        },
        error: function () {
            alertMessage("请检查网络连接！");
        }
    });
}

function showFilelot(clist) {
    var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
                chtml = chtml + '<tr>';
                chtml = chtml + '<td>' + clist[i].file_name + '</td>';
                chtml = chtml + '<td>' + clist[i].file_lot + '</td>';
                chtml = chtml + '<td>' + clist[i].productname + '</td>';
                chtml = chtml + '<td>' + clist[i].from_name + '</td>';
                chtml = chtml + '<td>' + clist[i].to_name + '</td>';
                chtml = chtml + '<td>' + clist[i].status + '</td>';
                chtml = chtml + '<td>';
                if(clist[i].status == '提交'){
                    chtml = chtml + '<button class="btn btn-danger" onclick="removefilelot(\'' + clist[i].id + '\');"><i class="fa fa-times"></i>删除</button>';
                }else if(clist[i].status == '完成'){
                    chtml = chtml + ' <button class="btn btn-info catTag" uid="' + clist[i].lot + '">完成</button>';
                }
                chtml = chtml + '</td>';
                chtml = chtml + '</tr>';
            }
        }
    }
    $("#filelotlist").html(chtml);
	InitHeight();
}

// 加载网点产品积分
function loadsitescore(){
    var datas = {access_token:getToken(),page_no:getPageNo()};
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/Shop/scorelist",
        dataType: 'json',
        data: datas,
        success: function (json) {
            if(json.result == "1"){
                scorelist = json.scorelist;
                showScore(scorelist);
                showpage(json.total_results,json.page_no,json.page_size,getwindowhref());
            }else{
                alertMessage(json.error_description);
            }

        },
        error: function () {
            alertMessage("请检查网络连接！");
        }
    });
}

function showScore(clist) {
    var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
                chtml = chtml + '<tr>';
                chtml = chtml + '<td>' + clist[i].branch_name + '</td>';
                chtml = chtml + '<td>' + clist[i].pname + '</td>';
                chtml = chtml + '<td>' + clist[i].score + '</td>';
                chtml = chtml + '<td>' + clist[i].start_date + '</td>';
                chtml = chtml + '<td>' + clist[i].end_date + '</td>';
                chtml = chtml + '<td>' + clist[i].status + '</td>';
                chtml = chtml + '<td>';
                chtml = chtml + '<button class="btn btn-info" onclick="editscore(\'' + clist[i].id + '\');"><i class="fa fa-edit"></i>编辑</button>&nbsp;&nbsp;&nbsp;&nbsp;';
                chtml = chtml + '<button class="btn btn-danger" onclick="removescore(\'' + clist[i].id + '\');"><i class="fa fa-times"></i>删除</button>';
                chtml = chtml + '</td>';
                chtml = chtml + '</tr>';
            }
        }
    }
    //alert(chtml);
    $("#scorelist").html(chtml);
	InitHeight();
}

var isContinueSync = false;
function sync() {
    var img = new Image();
    img.id = "test_is_online";
    img.onload = function () {
        document.body.removeChild(document.getElementById("test_is_online"));
        showLoading();
        $("#homepagemessageid").html("");
        $("#homepagemessageid").show();
        isContinueSync = true;

        upCompanyToServer();
        //if(isContinueSync) {
        upAllShipItemToServer();
        //}

        //if(isContinueSync) {
        loadCompany();
        //}

        //if(isContinueSync) {
        loadProduct();
        //}
        //hideLoading();

    };
    img.onerror = function () {
        document.body.removeChild(
                document.getElementById("test_is_online"));
        hideLoading();
        alert("请检查网络连接....");
    };
    img.src = "http://www.baidu.com/img/baidu_jgylogo3.gif";
    img.style.display = "none";
    document.body.appendChild(img);


}
/*
 * 按条件获取最新的文件
 */
function getfile(groupname){
    var chtml = '';
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/Company/getFile",
        dataType: 'json',
        data: 'access_token=' + getToken()+'&groupname='+groupname,
        success: function (json) {
            clist = json.filelist;
            if (!empty(clist)) {
                for (var i = 0; i < clist.length; i++) {
                    if (!empty(clist[i])) {
                        chtml = chtml + '<option value="'+clist[i].fileid+'">' + clist[i].note + '</optin>';

                    }
                }
            }
            $("#filename").append(chtml);
        },
        error: function () {
            alertMessage("请检查网络连接！");
        }
    });
}
/*
 * 按条件获取最新的图片
 */
function getpic(groupname,num){
    var ahtml = '';
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/Company/getpic",
        dataType: 'json',
        data: 'access_token=' + getToken()+'&groupname='+groupname +'&page_no='+num+'&page_size='+15,
        success: function (json) {
            piclist = json.piclist;
            showgetPic(piclist);
            var pages = Math.ceil(json.total_results/json.page_size);//这里data里面有数据总量
            if(pages>1){
                prvpage = num-1;
                if(prvpage>0){
                    ahtml = ahtml+'<li style="float:right;width:20%;line-height:30px;"><a href="javascript:void(0);" onclick="getpic(\''+groupname+'\','+ prvpage+')">'+'上一页</a></li>'
                }
                nextpage = num+1;
                if(nextpage<=pages){
                    ahtml = ahtml+'<li style="float:right;width:20%;line-height:30px;"><a href="javascript:void(0);" onclick="getpic(\''+groupname+'\','+ nextpage+')">'+'下一页</a></li>'
                }
            }
            //alert(pages);
            $("#getpicUl").html(ahtml);
        },
        error: function () {
            alertMessage("请检查网络连接！");
        }
    });
}

function showgetPic(clist) {
    piclist = clist;
    var chtml = '';
    if (!empty(clist)) {
        for (var i = 0; i < clist.length; i++) {
            if (!empty(clist[i])) {
            	chtml = chtml + '<li><img src="' + clist[i].image + '"></li>'
            	
//              chtml = chtml + '<tr>';
//              chtml = chtml + '<td><input class="form-control pics save" type="radio" name="pics" value="'+clist[i].image+'"/>' +  '</td>';
//              chtml = chtml + '<td>' + clist[i].title + '</td>';
//              chtml = chtml + '<td><img  width="60"  height="60" src="' + clist[i].image + '"></td>';
//              chtml = chtml + '</tr>';
            }
        }
    }else{
        chtm = '图片空间还没有对应图片' ;
    }
	
    $("#piclist").html(chtml);
    $('.ImageHosting').on('click',function(){
		$('.SlidingLayer').show();
		$('.AllContent').css({overflowY:'hidden'});
		
		var Slrw = $('.SlidingLayer ul li').width();
		$('.SlidingLayer ul li').height(Slrw);
		
		var pictImg = $('#piclist img').width();
		$('#piclist img').height(pictImg);
	});
	
	$('.SlidingLayer ul li img').on('click',function(){
		var thisImg = $(this).attr('src')
		$('#pic_url').attr({src:thisImg});
		$('#branch_pic').attr({src:thisImg});
		$('.SlidingLayer').hide();
		$('.AllContent').css({overflowY:'scroll'});
	});
	        
    $('.CloseImg').on('tap',function(){
		$('.SlidingLayer').hide();
		$('.AllContent').css({overflowY:'scroll'});
    });
}
/*
 * getsurplus 获取剩余标签数量
 */
function getsurplus(){
    $.ajax({
        type: "post",
        url: getServerUrl() + "/Open/Comtag/getsurplus",
        dataType: 'json',
        data: 'access_token=' + getToken(),
        success: function (json) {
            if(json.status == "1"){
                $("#surplusMeg").html('您还剩下'+json.surplus+'个标签码，如果不够要生成的数量请到用户中心充值');
                setCookie('Recharge',json.status);
                setCookie('surplus',json.surplus);
            }
        },
        error: function () {
            alertMessage("请检查网络连接！");
        }
    });
}

